import { RouteRecordRaw } from 'vue-router'

const pageTitle = (name: string): string => {
    return `pagesTitle.${name}`
}
/*
 * 静态路由
 */
const staticRoutes: Array<RouteRecordRaw> = [
    {
        // 管理员登录页
        path: '/login',
        name: 'login',
        component: () => import('/@/views/login.vue'),
        meta: {
            title: pageTitle('login'),
        },
    },
    {
        path: '/:path(.*)*',
        redirect: '/404',
    },
    {
        // 404
        path: '/404',
        name: 'notFound',
        component: () => import('/@/views/common/error/404.vue'),
        meta: {
            title: pageTitle('notFound'), // 页面不存在
        },
    },
    {
        // 后台找不到页面了-可能是路由未加载上
        path: '/:path(.*)*',
        redirect: (to) => {
            return {
                name: 'adminMainLoading',
                params: {
                    to: JSON.stringify({
                        path: to.path,
                        query: to.query,
                    }),
                },
            }
        },
    },
    {
        // 无权限访问
        path: '/401',
        name: 'noPower',
        component: () => import('/@/views/common/error/401.vue'),
        meta: {
            title: pageTitle('noPower'),
        },
    },
]

/*
 * 后台基础静态路由
 */
const adminBaseRoute: RouteRecordRaw = {
    path: '/',
    name: 'layout',
    component: () => import('/@/layouts/index.vue'),
    redirect: '/loading',
    meta: {
        title: pageTitle('admin'),
    },
    children: [
        {
            path: 'loading/:to?',
            name: 'adminMainLoading',
            component: () => import('/@/layouts/common/components/loading.vue'),
            meta: {
                title: pageTitle('Loading'),
            },
        },
        {
            path: 'dashboard',
            name: 'dashboard',
            component: () => import('/@/views/dashboard.vue'),
            meta: {
                title: pageTitle('dashboard'),
            },
        },
        {
            path: 'profile',
            name: 'profile',
            component: () => import('/@/views/profile.vue'),
            meta: {
                title: pageTitle('Profile'),
            },
        }
    ],
}
staticRoutes.push(adminBaseRoute)
export { staticRoutes, adminBaseRoute }
